package top.frsf.starter.impl;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import top.frsf.enums.GameStateEnum;
import top.frsf.object.plant.PlantObject;
import top.frsf.panel.GamePanel;
import top.frsf.starter.Starter;

import java.awt.*;
import java.util.ArrayList;

/**
 * 植物启动器
 *
 * @author FRSF
 * @since 2025/8/3 0:21
 */
@Data
@Slf4j
public class PlantStarter implements Starter {
    /**
     * 植物列表
     */
    private final ArrayList<PlantObject> plants = new ArrayList<>();
    /**
     * 死亡植物列表
     */
    private final ArrayList<PlantObject> deadPlants = new ArrayList<>();

    @Override
    public void init() {
        log.info("植物启动器初始化");
    }

    @Override
    public void start(Graphics graphics) {
        if (GamePanel.state == GameStateEnum.RUNNING) {
            plants.forEach(plant -> plant.paintSelfImage(graphics));
            plants.removeAll(deadPlants);
            deadPlants.clear();
        }
    }
}
